-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here

-- local keymap = vim.keymap.set
local remap = vim.api.nvim_set_keymap

local map = LazyVim.safe_keymap_set

map("n", "P", "'0p")
map("v", "P", "'0p")
map("n", ";f", "<C-f>")
map("n", ";b", "<C-b>")
map("n", ";", ":") --semicolon to enter command mode
map("n", "j", "gj") --move by visual line not actual line
map("n", "k", "gk")
map("n", "q", "<cmd>q<CR>")
map("n", "<leader>:", "<cmd>terminal<CR>")
remap("n", "<esc>", "<cmd>noh<CR><CR>", { noremap = true, silent = true })

--easymotion/hop
map("n", "gw", "<cmd>HopWord<CR>")
map("n", "gl", "<cmd>HopLine<CR>")
map("n", "g/", "<cmd>HopPattern<CR>")

-- bufferline
map("n", "<S-q>", "<cmd>BufferLineCloseLeft<CR>")
map("n", "<leader>bj", "<cmd>BufferLinePick<CR>")

-- git
map("n", "<leader>ga", "<cmd>Git add %:p<CR>")
map("n", "<leader>go", "<cmd>Git add .<CR>")
map("n", "<leader>gm", "<cmd>Git commit<CR>")
map("n", "<leader>gu", "<cmd>Git push<CR>")

map("n", "<leader>ns", "<cmd>lua require('package-info').show()<CR>")
map("n", "<leader>np", "<cmd>lua require('package-info').change_version()<CR>")
map("n", "<leader>ni", "<cmd>lua require('package-info').install()<CR>")

map("n", "<leader>ct", "<cmd>lua require('crates').toggle()<CR>")
map("n", "<leader>cv", "<cmd>lua require('crates').show_versions_popup()<CR>")

-- map("n", "<leader>mf", "<cmd>ReachOpen marks<CR>")
-- map("n", "<leader>bf", "<cmd>ReachOpen buffers<CR>")

map("n", "<leader>tw", "<cmd>Translate<CR>")

-- diffview
map("n", "<leader>td", "<cmd>DiffviewOpen<CR>")
map("n", "<leader>tD", "<cmd>DiffviewClose<CR>")

-- toggleterm
map("n", "<A-i>", "<cmd>ToggleTerm direction=float<CR>")
map("t", "<A-i>", "<C-\\><C-n><cmd>ToggleTermToggleAll<CR>")

-- barbar
-- local numbers = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }
-- for _, num in pairs(numbers) do
--   map("n", "<leader>" .. num, "<cmd>BufferGoto " .. num .. "<CR>")
-- end
-- map("n", "<leader>0", "<cmd>BufferGoto 10<CR>")

map("n", "gK", "<cmd>NodeAction<CR>")

-- menu
-- keymap("n", "<RightMouse>", function()
--   vim.cmd.exec('"normal! \\<RightMouse>"')
--
--   local options = vim.bo.ft == "NvimTree" and "nvimtree" or "default"
--   require("menu").open(options, { mouse = true })
-- end, {})
